﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>退回</title>
    <!--
    1, 退回界面。
    2，需要 FK_Flow, FK_Node,WorkID, FID.
    3, 调用方法 ReturnWork.htm?FK_Flow=001&FK_Node=103&WorkID=232&FID=23
    4. 确定按钮后，要关闭主窗口。
    5.当为父流程退回时，如果已经启动子流程时则不能执行退回功能
    6.当为子流程退回时，如果已经启动平级子流程时则不能执行退回功能
    7.退回到指定节点，如果退回到的节点中间有启动子流程或者平级子流程的节点，则不处理，正常退回
    -->
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>
    <script src="../Scripts/commonYangYH.js"></script>
    <!-- 导入配置文件. -->
    <!-- 该文件可以被集成厂商自己定义风格,可以自己修改,以达到流程设计器与自己的系统风格统一. -->
    <link href="../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>

    <!-- 加载通用的配置文件. -->
    <script type="text/javascript" src="../../DataUser/JSLibData/CommonShowConfig.js"></script>

    <script src="../InitMapAttr.js"></script>
    <link href="../Scripts/layui/layui/css/layui.css" rel="stylesheet" />
    <style type="text/css">
        body {
            background: transparent;
        }

            body div {
                text-align: left;
                margin: 20px auto;
            }

        #Message {
            width: 100%;
        }
    </style>
    <script type="text/javascript">

        function isExitsVariable(variableName) {
            try {
                if (typeof (eval(variableName)) == "undefined") {
                    console.log("已声明变量,但未初始化");
                    return false;
                } else {
                    console.log("已声明变量,且已经初始化");
                    return true;
                }
            } catch (e) {
                console.log("未声明变量");
            }
            return false;
        }

        var pageData = {};

        // ?
        var isFrameCross = GetQueryString("isFrameCross");

        var _ReturnWin_IsBackTracking_Selected = false;
        $(function () {

            try {
                _ReturnWin_IsBackTracking_Selected = ReturnWin_IsBackTracking_Selected;
            } catch (e) {
                _ReturnWin_IsBackTracking_Selected = false;
            }

            ////是否选择. 退回并原路返回. 强制设置，退回并原路返回.
            if (_ReturnWin_IsBackTracking_Selected == true) {
                document.getElementById("CB_IsBackTracking").checked = ReturnWin_IsBackTracking_Selected;
            }

            //初始化页面退回信息.
            pageData = {
                FK_Node: GetQueryString('FK_Node'),
                WorkID: GetQueryString('WorkID'),
                FID: GetQueryString('FID'),
                Message: GetQueryString('Info'),
                FK_Flow: GetQueryString("FK_Flow")
            };

            //如果有退回信息字段，就让其绑定到，退回原因的文本框里.
            if (pageData.Message != undefined && pageData.Message != '') {
                $('#TB_Doc').val(pageData.Message);
            }

            //调用接口，传入url的参数。
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData(); //FK_Flow, FK_Node,WorkID,Info info=退回信息字段.

            //初始化数据.
            var data = handler.DoMethodReturnString("Return_Init");

            if (data.indexOf('info@') == 0) {

                //这种情况下，有可能是自动退回，自动退回就提示退回消息.

                //设置弹出框的大小
                $(".modal-content", parent.document).css("width", "");
                $(".modal-content", parent.document).css("height", "300px");

                $("#iframeReturnWorkForm", parent.document).css("height", "300px");

                data = data.replace('info@', '');
                data = data.replace(/null/g, '');
                data = "<font>" + data + "</font>";
                $("#Msg").html("");
                $("#DIV_Nodes").html(data);
                $("#DIV_Doc").html("");
                $("#btnReturn").css("display", "none");

                // $("#btnIsBackTracking").css("display", "block");
                //$("#btnIsKillEtcThread").css("display", "block");

                $("#btnClose").attr("onclick", "Close(1)");
                return;
            }

            //对与非法的调用，系统会提示，比如：不应该退回而退回，已经发送到下一个节点还要执行退回等等.
            if (data.indexOf('err@') == 0) {
                //console.error("退回窗口错误信息" + data);
                data = data.replace('err@', '');
                data = "<font color=red>" + data + "</font>";
                $("#Msg").html(data);
                //  alert(data);
                return;
            }

            //启用了退回扩展字段,  退回的考核信息，就是扩充了其他的字段，这里不翻译了.
            var node = new Entity("BP.WF.Node", pageData.FK_Node);

            if (node.IsKillEtcThread == 1 || node.IsKillEtcThread == "1") {
                //alert(node.IsKillEtcThread);
                //  document.getElementById("btnIsKillEtcThread").style.display = 'none';
                //  arget.style.display="none";
                // $("#btnIsKillEtcThread").css("display", "none");
            }


            if (node.ReturnCHEnable == 1) {
                var mapAttrs = new Entities("BP.Sys.MapAttrs");
                mapAttrs.Retrieve("FK_MapData", "BP.WF.ReturnWorks", "Idx");
                var idx = 0;
                if (mapAttrs.length != 0) {
                    $("#ReturnCH").show();
                    var html = " 退回考核规则信息：";
                    html += "<table style='width:100%;'>";
                    for (var i = 0; i < mapAttrs.length; i++) {
                        if (mapAttrs[i].AtPara.indexOf("FK_Flow=" + pageData.FK_Flow) != -1) {
                            idx++;
                            if ((idx + 1) % 2 == 0)
                                html += "<tr>";
                            html += "<td>" + mapAttrs[i].Name + "</td>";
                            html += "<td  style='text-align:left'>";
                            html += InitAthMapAttrOfCtrlFool(null, mapAttrs[i], null);
                            html += "</td>";
                            if (idx % 2 == 0)
                                html += "</tr>";
                        }

                    }
                    html += "</table>";
                    if (idx != 0) {
                        $("#ReturnCH").html(html);
                    }
                }
            }

            //获得可以退回的节点集合。
            var returnNodeArr = JSON.parse(data);
            var nodeListHtml = '';

            $.each(returnNodeArr, function (i, returnNode) {

                if (returnNode.AtPara && returnNode.AtPara.indexOf('IsHuiQian=1') >= 0) {
                    return true; //退回这个字段里包含 IsHuiQian=1的字符，就排除掉.
                }

                if (nodeListHtml.indexOf(returnNode.No + '@') != -1)
                    return true;

                nodeListHtml += '<option data-IsKillEtcThread=' + returnNode.IsKillEtcThread + ' data-IsBackTracking=' + returnNode.IsBackTracking + ' value="' + returnNode.No + '@' + returnNode.Rec + '">' + returnNode.RecName + '=&gt;' + returnNode.Name + '</option>';
            });

            //绑定退回到节点的数据.
            $('#DDL_Nodes').html(nodeListHtml);

            //获取当前节点属性,是否可以执行退回并原路返回的按钮？
            var node = new Entity("BP.WF.Node", pageData.FK_Node)
            if (node.IsBackTracking == "0")
                $('#btnIsBackTracking').css('display', 'block');

            if (node.IsKillEtcThread == "0")
                $('#btnIsKillEtcThread').css('display', 'block');

            $("section").show();
            $(".wait").hide();

            Common.MaxLengthError();
        });
        //确定 退回 执行退回操作
        // isBack=0 是退回按钮调用， =1是退回并原路返回按钮调用.
        function Save(isBack) {

            //判断退回并原路返回复选框是否被选中
            if ($("#CB_IsBackTracking").prop("checked") == true)
                isBack = 1;

            //是否全部（子线程）退回？
            var IsKillEtcThread = 0;
            if ($("#CB_IsKillEtcThread").prop("checked") == true)
                IsKillEtcThread = 1;

            //获得选择退回的节点.
            var selectedNodeID = $('#DDL_Nodes').val();
            if (selectedNodeID == null || selectedNodeID == undefined || selectedNodeID == "") {
                alert('请选择要退回的节点');
                return;
            }

            //获得退回原因.
            var val = escape($('#TB_Doc').val().trim());
            if (val == null || val == "" || val == undefined) {
                alert("请输入退回原因.");
                return;
            }

            $('.foot input').attr('disabled', 'disabled');
            $('.foot input').css('background', 'gray');
            var doc = "";
            if (plant == 'CCFlow') {
                doc = escape($('#TB_Doc').val());
            } else {
                doc = $('#TB_Doc').val();
            }

            //调动退回接口.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddPara("FK_Flow", pageData.FK_Flow);
            handler.AddPara("WorkID", pageData.WorkID);
            handler.AddPara("FID", pageData.FID);
            handler.AddPara("FK_Node", pageData.FK_Node);
            handler.AddPara("ReturnToNode", selectedNodeID);
            handler.AddPara("ReturnInfo", doc);

            //如果强制设置了退回并原路返回.
            if (_ReturnWin_IsBackTracking_Selected != undefined && _ReturnWin_IsBackTracking_Selected == true)
                isBack = 1;

            handler.AddPara("IsBack", isBack);

            //是否全部子线程退回？
            handler.AddPara("IsKillEtcThread", IsKillEtcThread);
            //  alert(IsKillEtcThread);

            //增加字段属性, 这部分，vue可以不翻译.
            var parasData = $("form").serialize();
            handler.AddPara("PageData", parasData);

            //调用退回方法.
            var data = handler.DoMethodReturnString("DoReturnWork"); //执行方法.
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.WindowCloseReloadPage != null && typeof window.parent.WindowCloseReloadPage === "function") {
                    window.parent.WindowCloseReloadPage(data);
                } else {
                    if (typeof WindowCloseReloadPage != 'undefined'
                        && WindowCloseReloadPage instanceof Function)
                        WindowCloseReloadPage(data);
                }
            } else {
                ChildrenPostMessage(data, "WindowCloseReloadPage");
            }


            //提示退回消息， 并关闭窗口，刷新父父窗口.
            data = data.replace(/null/g, '');
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    window.parent.returnWorkWindowClose(data);
                } else if (window.opener != undefined && window.opener.returnWorkWindowClose != undefined) {
                    window.opener.returnWorkWindowClose(data);
                } else {
                    $('body').append($('<div>' + data + '</div>'));
                    $('#btnOk').attr('disabled', true);
                }
            } else {
                ChildrenPostMessage(data, "returnWorkWindowClose");
            }


            $(".foot").hide();
        }

        //取消退回
        function Close(flag) {
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    window.parent.returnWorkWindowClose("取消");
                    if (flag == 1)
                        window.parent.close();
                }
                else {
                    $('body').append($('<div>' + "已取消操作" + '</div>'));
                    window.close();
                }
            } else {
                ChildrenPostMessage("取消", "returnWorkWindowClose");
                if (flag == 1)
                    window.parent.close();
            }

        }


    </script>
</head>
<body>
    <div style="padding:0 15px;">
        <div class="wait" style="text-align: center;" id="Msg">页面数据正在加载中，请稍候......</div>
        <div id="DIV_Nodes">
            要退回到:
            <select id="DDL_Nodes" name="DDL_Nodes" style="width: 60%;border:solid 1px #ccc" class="layui-select"></select>
        </div>
        <!--启用了退回考核规则的设置-->
        <form id="cc">
            <div id="ReturnCH" style="display:none;"></div>
        </form>

        <div id="DIV_Doc">
            <textarea id="TB_Doc" name="TB_Doc" placeholder="请输入退回原因..."
                      style="width: 100%; height:150px;border:solid 1px #ccc"
                      maxlength="500" class="layui-textarea"></textarea>
        </div>
    </div>

    <!--<div> 上传附件：</div>
        <div style="height:100px;">上传附件预留：该功能正在建设中</div>
    -->

    <div class="form-inline" style="position: fixed;right: 10px;bottom: 40px;">

        <div id="btnIsBackTracking" style="margin-top:6px;float:left; display:none;">
            <label>
                <input type="checkbox" id="CB_IsBackTracking" style="float:left;margin-top:3px;" />
                退回后并发送给我&nbsp;&nbsp;
            </label>
        </div>

        <div id="btnIsKillEtcThread" style="margin-top:6px;float:left; display:none;">
            <label>
                <input type="checkbox" id="CB_IsKillEtcThread" style="float:left;margin-top:3px;" />
                全部子线程退回&nbsp;&nbsp;
            </label>
        </div>


        <button type="button" onclick="Close();" id="btnClose" class="layui-btn layui-btn-primary">
            <!--<img src="../Img/Btn/Close.png" />--> 关闭
        </button>
        <button type="button" onclick="Save(0);" id="btnReturn" class="layui-btn layui-btn-normal">
            <!--<img src="../Img/Btn/Confirm.png" />--> 退回
        </button>
    </div>

</body>
</html>
